﻿(function () {
    "use strict";

    WinJS.UI.Pages.define("/pages/itemDetail/itemDetail.html", {
        // This function is called whenever a user navigates to this page. It
        // populates the page elements with the app's data.
        ready: function (element, options) {
            Debug.resetClock();
            var item = options.item;
            element.querySelector('.pagetitle').textContent = item.zip;
            element.querySelector('.pagesubtitle').textContent = item.city + ", " + item.state;
            element.querySelector('.satellite').style.backgroundImage = item.satellite;

            // get US Census data for population by age and gender
            Data.getPopulationData(item).then(
                function (result) {
                    populationGraph.winControl.data = result;
                    return (result) ? true : false;
                },
                function (error) { console.error('Error: getPopulationData()', Debug.clock()); return false; }
            ).done(
                function (success) {
                    if (success) return;
                    population.className += ' noData';
                    population.innerHTML = 'No Data';
                }
            );

            // get US Census data for commute 
            Data.getCommuteData(item).then(
                function (result) {
                    commuteGraph.winControl.data = result;
                    return (result) ? true : false;
                },
                function (error) { console.error('Error: getCommuteData()', Debug.clock()); return false; }
            ).done(
                function (success) {
                    if (success) return;
                    commute.className += 'noData';
                    commute.innerHTML = 'No Data';
                }
            );

            // get US Census data for rent vs. own
            Data.getHousingData(item).then(
                function (result) {
                    housingGraph.winControl.data = result;
                    return (result) ? true : false;
                },
                function (error) { console.error('Error: getHousingData()', Debug.clock()); return false }
            ).done(
                function (success) {
                    if (success) return;
                    housing.className += 'noData';
                    housing.innerHTML = 'No Data';
                }
            );
        }
    });
})();
